# -*- coding: utf-8 -*-
  # -*- coding: utf-8 -*-
from google.appengine.ext import db
from google.appengine.api import users

CATEGORY_CHOICES = (
  ('utilities', 'Utilities'),
  ('virus', 'Virus Removal Tools'),
  ('hdd', 'Hard Drive Diagnostics'),
  ('live', 'Live Linux OS'),
  ('linux', 'Linux Installers'),
  ('misc', 'Miscellaneous'),
)

# Create your models here.
class Tool(db.Model):
  name = db.StringProperty(required=True)
  #The name to boot from commandline
  quick_name = db.StringProperty()
  #Description to go show when the tool is highlighted
  description = db.StringProperty(required=True)
  #Change this to a combo box
  default_category = db.StringProperty(required=True, choices=CATEGORY_CHOICES)
  #Path to kernel (or possibly memdisk)
  path = db.URLProperty(required=True)
  #Path to initrd, if available
  initrd_path = db.URLProperty()
  #Kernel args to append after initrd
  append_args = db.StringProperty()
  #Whether tools is available to other users
  public = db.BooleanProperty(required=True)
  #Owner of the tool (always available to that user)
  owner = db.UserProperty(required=True)
	
  def __unicode__(self):
    return self.name
	
class Menu(db.Model):
  #Need some way to check which public tools have been added to this user.  Should be easy with ManyToManyFields
  
  #Title of the menu
  title = db.StringProperty(required=True)
  #Timeout in 1/10 of second
  timeout = db.IntegerProperty(required=True)
  #Whether users are allowed to drop down into a command prompt
  prompt = db.BooleanProperty(required=True)
  #URL to background file
  backgroud_url = db.URLProperty()
  #URL to menu file (vesamenu.c32 or menu.c32)
  menu_file = db.URLProperty(required=True)
  #Owner of the menu
  owner = db.UserProperty(required=True)
  
  #Need a good way around this..probably a List, and storing a full copy of the menu, and regenerating as required
  #included_tools = models.ManyToManyField(Tool)

  def __unicode__(self):
    return self.title

class Machine(db.Model):
  #MAC address
  identifier = db.StringProperty(required=True)
  #Name of the machine, if set by user.
  name = db.StringProperty(required=True)
  #Last image that was booted
  last_image = db.URLProperty()
  #Next image to be booted (if user wants autoboot next time)
  next_image = db.URLProperty()
  #Expiry for next image booting
  next_expire = db.DateTimeProperty()
  #Owner of the machine, allowed to update the machine, shown machine
  owner = db.UserProperty(required=True)
  
  def __unicode__(self):
    if (self.name == None):
      return self.name
    else:
      return self.identifier
      
DEB_LOCALE = (
  ('US English', 'en_US'),
)
DEB_KEYBOARD_CODE = (
  ('us', 'US'),
)
DEB_KEYBOARD_CODE_VARIANT = (
  ('dvorak', 'Dvorak'),
)
DEB_CLOCK_TIMEZONE = (
  ('US/Central', 'US/Central'),
  ('US/Eastern', 'US/Eastern'),
)
DEB_PARTITION_METHOD = (
  ('regular', 'Regular Partitions'),
  ('lvm', 'Logical Volume Manager (LVM)'),
  ('crypto', 'Encrypted Drive'),
)
DEB_PARTITION_RECIPE = (
  ('atomic', 'All files in one partition'),
  ('home', 'Separate /home partition'),
  ('multi', 'Separate /home, /usr, /var, and /tmp partitions'),
)
DEB_PARTITION_FILESYSTEM = (
  ('ext3', 'ext3'),
  ('ext4', 'ext4'),
)
DEB_TASKSEL = (
  ('ubuntu-desktop', 'Standard (Gnome) Desktop'),
  ('ubuntu-server', 'Base Server'),
  ('kubuntu-desktop', 'KDE Desktop'),
)
DEB_UPGRADE_PACKAGES = (
  ('none', 'None'),
  ('safe-upgrade', 'Safe Upgrade'),
  ('full-upgrade', 'Full Upgrade'),
)
class UbuntuPreseed(db.Model):
  name = db.StringProperty(required=True)
  locale = db.StringProperty(required=True, choices=DEB_LOCALE)
  #Set keyboard detection false
  ### d-i console-setup/ask_detect boolean false
  keyboard_code = db.StringProperty(required=True, choices=DEB_KEYBOARD_CODE)
  keyboard_code_variant = db.StringProperty(required=True, choices=DEB_KEYBOARD_CODE_VARIANT)
  #Chose interface
  ### d-i netcfg/choose_interface select auto
  clock_utc = db.BooleanProperty(required=True)
  clock_timezone = db.StringProperty(required=True, choices=DEB_CLOCK_TIMEZONE)
  
  #Remove this or change it to Advanced, not using currently
  clock_ntp = db.BooleanProperty(required=True)
  
  #Auto partition format, where XXX is the choice
  ### d-i partman-auto/method string XXX
  partition_method = db.StringProperty(required=True, choices=DEB_PARTITION_METHOD)
  #Auto remove old LVM, RAID, etc
  ### d-i partman-lvm/device_remove_lvm boolean true
  ### d-i partman-md/device_remove_md boolean true
  #Write LVM
  ### d-i partman-lvm/confirm boolean true
  partition_recipe = db.StringProperty(required=True, choices=DEB_PARTITION_RECIPE)
  partition_filesystem = db.StringProperty(required=True, choices=DEB_PARTITION_FILESYSTEM)
  #Auto apply partition recipe, method, and filesystem
  ### d-i partman/confirm_write_new_label boolean true
  ### d-i partman/choose_partition select finish
  ### d-i partman/confirm boolean true
  ### d-i partman/confirm_nooverwrite boolean true
  user_full_name = db.StringProperty(required=True)
  user_name = db.StringProperty(required=True)
  user_crypted_password = db.StringProperty(required=True)
  #Allow weak password
  ### d-i user-setup/allow-password-weak boolean true
  encrypt_home = db.BooleanProperty()
  tasksel = db.StringProperty(required=True, choices=DEB_TASKSEL)
  upgrade_packages = db.StringProperty(required=True, choices=DEB_UPGRADE_PACKAGES)
  #Installs Grub to MBR if safe
  ### d-i grub-installer/only_debian boolean true
  #Installs Grub to MBR if other OS, tries to add both to menu_file
  ### d-i grub-installer/with_other_os boolean true
  # Avoid that last message about the install being complete.
  ### d-i finish-install/reboot_in_progress note
  # Monitor autodetection is recommended.
  ### xserver-xorg xserver-xorg/autodetect_monitor boolean true
  # Uncomment if you have an LCD display.
  #xserver-xorg xserver-xorg/config/monitor/lcd boolean true
  # X has three configuration paths for the monitor. Here's how to preseed
  # the "medium" path, which is always available. The "simple" path may not
  # be available, and the "advanced" path asks too many questions.
  ### xserver-xorg xserver-xorg/config/monitor/selection-method \
	### select medium
  ### xserver-xorg xserver-xorg/config/monitor/mode-list \
	### select 1024x768 @ 60 Hz
	
  #d-i preseed/late_command string wget URL/SCRIPT.sh
  #d-i preseed/late_command sh SCRIPT.sh
  
  #Need to add:
  ## Hostname
  ## Domain
  
  final_script = db.URLProperty()
  owner = db.UserProperty(required=True)
  
  def __unicode__(self):
    return self.name
